package com.cb.controller.admin.system;


import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.cb.core.controller.BaseFormController;
import com.cb.domain.model.system.SystemHelp;
import com.cb.domain.service.system.SystemHelpManager;

/**
 * 
 * @Author author name
 * Create Time:
 * <p>Class Description Here [TODO]</p>
 */
public class SystemHelpFormController extends BaseFormController {
	
	@Autowired
	private SystemHelpManager systemHelpManager=null;
	
	public SystemHelpFormController() {
		 setCommandName("systemHelp");
	     setCommandClass(SystemHelp.class);
	}
	
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		
		SystemHelp systemHelp=(SystemHelp)command;
		String msg=null;
		//validate the logic business data here [TODO]
		if(systemHelp.getSystemId()==null){
			msg=getText("systemHelp.added",systemHelp.getTitle());
		
		}else{
			msg=getText("systemHelp.updated",systemHelp.getTitle());
		}
		systemHelp.setCreateDate(new Date());
		systemHelpManager.save(systemHelp);
		
		saveMessage(request,msg);
		
		return new ModelAndView(getSuccessView());
	}
	
	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		SystemHelp systemHelp=null;
		String systemId=request.getParameter("systemId");
		if(StringUtils.isNotEmpty(systemId)){
			systemHelp=systemHelpManager.get(new Long(systemId));
		}else{
			systemHelp=new SystemHelp();
		}
		return systemHelp;
	}
	
}
